<?php
$userid = $this->session->userdata('id');
$searchTrem = '';
$sortBy = 'date';
$order = 'desc';
$page = 0;
$status = 'residential';
$loadUrl = base_url() . 'index.php/property/load/' . $status . '/' . $page;
?>
<script type="text/javascript">
    $(document).ready(function() {
        autocomplate('suburbs');
        $('#seachvals :input').keypress(function(e) {
            if (e.which == 13) {
                e.preventDefault();
                searchListing();
            }
        });

        $('#suburbs').keypress(function(e) {
            if (e.which == 13) {
                e.preventDefault();
                searchListing();
            }
        });

        $("#suburbs").autocomplete({
            delay: 100,
            source: function(request, response) {
                $.ajax({
                    url: "<?php echo site_url('home/ajax_search?part=') ?>" + request.term,
                    dataType: 'json',
                    success: function(json) {
                        response($.map(json, function(item, key) {
                            return {
                                label: item,
                                values: key
                            }
                        }));
                        return false
                    }
                });
            },
            select: function(event, ui) {
                $("#suburbs_id").val(ui.item.values);
            },
            focus: function(event, ui) {
                return false;
            }
        });

    });

    function searchListing() {
        var sortby = $('#sortBy').val();
        var order = $('#orderBy').val();
        var selValue = $('input[name=type]:checked').val();
        if (selValue == 'rentals') {
            $("#seachvals").attr("action", "<?= base_url() ?>index.php/tenant/rentals/show");
            $("#seachvals").submit();
        } else {
            $("#seachvals").attr("action", "<?= base_url() ?>index.php/buying/listings/show");
            $("#seachvals").submit();
        }



    }





</script>
<script type="text/javascript">
var refreshIntervalId;
$(document).ready(function() {		
	
	//Execute the slideShow
	slideShow();
	
	$('#gallery a').mouseover(function(){
		window.clearInterval(refreshIntervalId);
	})
	
	$('#gallery a').mouseout(function(){
		slideShow();
	})
});

function slideShow() {

	//Set the opacity of all images to 0
	$('#gallery a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#gallery a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#gallery .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	//$('#gallery .content').html($('#gallery a:first').find('img').attr('rel'))
	//.animate({opacity: 0.7}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	refreshIntervalId = setInterval('gallery()',5000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));	
	
	//Get next image caption
	//var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	
	//Display the content
	$('#gallery .content').html(caption);
	
	
}

</script>
<div class="content">
    <div class="contenttop">
        <div class="contentleft">
            <div class="banner">


                <div id="gallery">
                        <?php
                        foreach ($bannerSlides as $bannerSlide) {
                            $banner = $bannerSlide->image_url;
                            $property_id = $bannerSlide->property_id;
                            ?>
                       <a href="<?php echo site_url('property/profile/listings/'.$property_id) ?>" >

                        <?php
                            if ($banner != '') {
                                ?>

                                <img src="<?php echo $banner; ?>"  width="610" height="315" />
                                <?php
                            } else {
                                ?>
                                <img src="<?php echo base_url(); ?>img/banner.jpg" alt="" width="610" height="315"/>
                                <?php
                            }
                            ?>
                                </a>
                                <?php
                        } // foreach
                        ?>
                    
                </div>
            </div>
            <div class="maincontent">
                <h1>How much will you save with Go Gecko</h1>
                <p><div id="state_message_default" >Our savings are based on Qld Industry Standard Maximum Commission charged at 5% of the first $18,000 + 2.5% of the balance of the settled price + 10% GST. For a Fair Go - Go Gecko.</div>
                <div id="state_message" ></div>
                </p>
            </div>
        </div>
        <div id="search-properties">
            <h3>Quick Search</h3>
            <form id="seachvals" action="#" method="post">
                <div class="clearfix" id="searchform-title">
                    <span> 
                        <label>
                            <input type="radio" class="type" checked="checked"  value="listings" name="type" />
                            Buy
                        </label> 
                        <label>
                            <input type="radio" class="type" value="rentals" name="type" />
                            Rent
                        </label>
                    </span> 
                    <span> 
                        <label>
                            <input type="checkbox" checked="checked" value="1" name="surrounding" id="surrounding"  />
                            Surrounding suburbs
                        </label>
                    </span>
                </div>
                <div id="searchform-box">
                    <input type="text" 
                           data-input-type="autocomplete"
                           placeholder="Suburb/Town" 
                           name="suburbs"
                           class="col2 ui-autocomplete-input"
                           id="suburbs" 
                           autocomplete="off"
                           role="textbox" 
                           aria-autocomplete="list" 
                           aria-haspopup="true" /> 

                    <input type="hidden" 
                           data-for="property-search-autocomplete"
                           data-input-type="autocomplete-value" 
                           name="suburb" />
                    <input type="hidden" id="suburbs_id" value="<?php echo!empty($post['suburbs_id']) ? $post['suburbs_id'] : '' ?>" name ="suburbs_id">
                    <div id="results-suburbs"></div>
                </div>
                <p>Property Type</p>
                <?= form_dropdown('search_propertytype', $propertyType, '', 'id="search_propertytype"'); ?>
                <table>
                    <tr>
                        <td><label>Minimum Price:</label> 
                            <?= form_dropdown('search_minprice', $Minprice, '', 'id="search_minprice" class="sale"'); ?>

                        </td>
                        <td><label>Maximum Price:</label> 
                            <?= form_dropdown('search_maxprice', $Maxprice, '', 'id="search_maxprice" class="sale column-end"'); ?>

                        </td>
                    </tr>

                    <tr>
                        <td><label>Bedrooms:</label> 
                            <?= form_dropdown('search_bedroom', $BedroomCount, '', 'id="search_bedroom" class="last"'); ?>                            
                        </td>
                        <td><label>Bathrooms:</label> 
                            <?= form_dropdown('search_bathroom', $BathroomCount, '', 'id="search_bathroom" class="last"'); ?>

                        </td>
                    </tr>

                </table>                
                <input type="hidden" name="sortBy" id="sortBy" value="date" />
                <input type="hidden" name="orderBy" id="orderBy" value="desc" />
                <input type="button" value="search" name="search" onClick="searchListing()"  class="orange-button last" />
            </form>
            <div class="clearer"></div>
        </div>
        <script type="text/javascript">// <![CDATA[
    $(document).ready(function() {
        $('select[name="calculator-state"]').change(getstate);
        $('select[name="calculator-sales"]').change(getstate);
    });

    //The function that handles the process
    function getstate(event)
    {
        //Stop the form from submitting
        event.preventDefault();

        //Collect our form data.
        var form_data = {
            calculator_state: $('select[name="calculator-state"]').val(),
            calculator_sales: $('select[name="calculator-sales"]').val(),
        };

        //Begin the ajax call
        $.ajax({
            url: "<?php echo site_url('home/calculator_ajax') ?>",
            type: "POST",
            data: form_data,
            dataType: "json",
            cache: false,
            success: function(json) {
                if (json.error == 1)
                {

                } else {
                    //Hide our form
                    // $('#registerModalform').slideUp();
                    //Show the success message
                    $('#save_values_default').hide();
                    $('#state_message_default').hide();
                    $('#save_values').html(json.save_values).show();
                    $('#state_message').html(json.state_message).show();

                }
            }
        });
    }

    // ]]>
        </script>
        <div class="calculator">
            <div class="state-input">
                <?php echo form_open(site_url('home/index')); ?>
                <?php echo $state; ?>
                <br /> 
                <?php echo $sales; ?>
                <?php echo form_close(); ?> 
            </div>
            <div class="savings">
                <h2>You Save</h2>
                <div class="value">
                    <span class="dollars"></span> <span data-input-type="label"
                                                        class="result"><div id="save_values_default" >$ 840</div>
                        <div id="save_values" ></div></span>
                    <div class="clearer"></div>
                </div>
                <div class="clearer"></div>
            </div>
            <div class="clearer"></div>
        </div>


        <div class="clearer"></div>
    </div>
    <div class="contentbottom">
        <div class="latestnews">
            <h3>Latest News :</h3>
            <div class="homeowner">
                <h4><?php echo $newshomelastest_headline; ?></h4>
                <p><?php echo $newshomelastest_subject; ?></p>
                <a href="<?= site_url('news/latest') ?>" class="readmore"><img src="<?php echo base_url(); ?>img/arrow.png" alt=""
                                                                               style="vertical-align: middle; padding: 0px 5px 5px 0px;" />read
                    more</a>
            </div>
            <div class="clearer"></div>
        </div>
        <div class="subscribe">
            <a href="<?= site_url('landlord/propertymanagement') ?>"><img src="<?php echo base_url(); ?>img/property-alert1.png" alt="" title="Landlord Information" />
            </a><a href="<?= site_url('selling/appraisal') ?>"><img src="<?php echo base_url(); ?>img/property-alert2.png" alt=""  title="Free Market Appraisal" style="padding: 0px 12px;" />
            </a> 
            <a href="#" onclick="$('#subscribe-dialog-modal').dialog('open');
        return false;" class="isubscribe">
                <span class="iisubscribe">Subscribe to<br />our Property Alerts</span>
            </a>
            <div id="subscribe-dialog-modal" title="Subscribe to our Property Alerts">
                <div class="showError"></div>
                <div class="subscribe_form">
                    <?php echo form_open('subscribe/insert', 'id=subscribe'); ?>
                    <table>
                        <tr>
                            <td colspan="2">
                                Hot properties, news and real estate trends delivered straight to your inbox.
                            </td>
                        </tr>
                        <tr>
                            <td style="padding-top:8px">
                                full name
                            </td>
                            <td style="padding-top:8px">
                                <input id="subscribe_name" name="subscribe_name" type="text" value="<?php echo set_value('subscribe_name'); ?>" style="width:240px"/>
                            </td>
                        </tr>
                        <tr>
                            <td style="padding-top:8px">
                                email
                            </td>
                            <td style="padding-top:8px">
                                <input id="subscribe_email"  name="subscribe_email" type="text" value="<?php echo set_value('subscribe_email'); ?>" style="width:240px"/>
                            </td>
                        </tr>
                    </table>
                    <?php echo form_close(); ?>
                    <br/>
                    <div id="subscribeModalerror" class="error" style="display: none; text-align: left;"></div>

                    <?php echo validation_errors('<p class="error">'); ?>
                </div>
            </div>
            <script>
    $("#subscribe-dialog-modal").dialog({
        autoOpen: false,
        width: 400,
        height: 280,
        modal: true,
        resizable: false,
        buttons: {
            Subscribe: function() {

                $('#subscribe').submit();
                //$(this).dialog("close"); 
            },
            Cancel: function() {
                $(this).dialog("close");
            },
        }
    });
    //Wait until the DOM is fully loaded
    $(document).ready(function() {
        //Listen for the form submit
        $('.showError').html('');
        $('#subscribe').submit(submitSubscribeEmail);

    });

    function submitSubscribeEmail() {
        if (validateForm()) {
            subscribeEmail();
            showmessage('save_success', 'Task saved', 'The task details are saved');
            return false;
        } else {
            showmessage('error', 'Task saved', 'The task details are saved');
            return false;
        }
    }
    //The function that handles the process
    function subscribeEmail(event)
    {

        //Stop the form from submitting
        //  event.preventDefault();

        //Collect our form data.
        var form_data = {
            subscribe_name: $("[name='subscribe_name']").val(),
            subscribe_email: $("[name='subscribe_email']").val(),
        };

        //Begin the ajax call
        $.ajax({
            url: "<?php echo site_url('subscribe/subscribe_ajax') ?>",
            type: "POST",
            data: form_data,
            dataType: "json",
            cache: false,
            success: function(json) {
                if (json.error == 1)
                {
                    //Show the user the errors.
                    $('.showError').html(json.message);
                    $('.showError').show();

                } else {
                    //Hide our form
                    $('#registerModalform').slideUp();
                    //Show the success message
                    $('.showSuccess').html(json.message).show();
                    $('#subscribe_name').val('');
                    $('#subscribe_email').val('');
                    $('.showError').html('');
                    $("#subscribe-dialog-modal").dialog('close');
                    $("#success-dialog-modal").dialog('open');
                }
            }
        });
    }
    function showmessage(type, title, desc) {
        $("#msgicon").attr("src", "<?php echo base_url(); ?>img/sev/" + type + ".jpg");
        $("#msgtitle").html(title);
        if (type == 'save_success' || type == 'success')
            $("#msgtitle").css("color", "green");
        else if (type == 'warn')
            $("#msgtitle").css("color", "darkorange");
        else if (type == 'error' || type == 'fatal')
            $("#msgtitle").css("color", "darkred");
        else
            $("#msgtitle").css("color", "#0000a0");
        $("#msgdesc").html(desc);
        $("#msgContainer").css("display", "block");
    }
    function hidemessage() {
        $("#msgContainer").css("display", "none");
    }
    function checkLength(o, n, min, max) {
        if (o.val().length > max || o.val().length < min) {
            o.addClass("ui-state-error");
            updateTips("Length of " + n + " must be between " +
                    min + " and " + max + ".");
            return false;
        } else {
            return true;
        }
    }
    function validateForm() {
        var subscribe_name = $('#subscribe_name').val();
        var subscribe_email = $('#subscribe_email').val();

        if (subscribe_name == '') {
            $('#subscribe_name').attr("class", "error");
            $('#subscribe_name').focus();
            $('.showError').html('Please enter the full name');
            return false;
        } else {
            $('#subscribe_name').attr("class", "mandatory");
        }

        if (subscribe_email == '') {
            $('#subscribe_email').attr("class", "error");
            $('#subscribe_email').focus();
            $('.showError').html('Please enter the email');
            return false;
        } else {
            $('#subscribe_email').attr("class", "mandatory");
        }
        return true;
    }

            </script>
        </div>
        <div class="clearer"></div>
    </div>
</div>
